<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<template>
  <!-- 店铺设置 -->
  <view class="Mall4j page-store-settings shop-setting-module">
    <view class="header">
      <view class="shop-basic-con">
        <view class="shop-logo">
          <img-show
            :src="userInfo.shopLogo"
            :def-img-inx="2"
          />
        </view>
        <view class="con">
          <view class="shop-name">
            {{ userInfo.shopName?userInfo.shopName:userInfo.userName }}
          </view>
          <!-- <view class="shop-desc">(营业中，账号已启用，店铺已审核)</view> -->
          <view class="shop-desc">
            (
            <text v-if="userInfo.shopStatus===-1">
              未开通
            </text>
            <text v-if="userInfo.shopStatus===0">
              停业中
            </text>
            <text v-if="userInfo.shopStatus===1">
              营业中
            </text>
            <text v-if="userInfo.shopStatus===2">
              违规下线
            </text>
            <text v-if="userInfo.shopStatus===3">
              上线待审核
            </text>
            <text v-if="userInfo.shopStatus===4">
              开店申请中
            </text>
            <text v-if="userInfo.shopStatus===5">
              开店待审核
            </text>

            <text v-if="userInfo.accountStatus===1">
              ，账号已启用
            </text>
            <text v-if="userInfo.accountStatus===0">
              ，账号已禁用
            </text>
            <text v-if="userInfo.accountStatus===-1">
              ，账号已删除
            </text>

            <text v-if="auditingInfoStatus===0">
              ，店铺未审核
            </text>
            <text v-if="auditingInfoStatus===1">
              ，店铺已审核
            </text>
            <text v-if="auditingInfoStatus===-1">
              ，店铺审核未通过
            </text>
            <text v-if="auditingInfoStatus===-2">
              ，店铺未提交审核
            </text>
            )
          </view>
        </view>
      </view>
    </view>
    <!-- 菜单 -->
    <view class="setting-menu">
      <block
        v-for="item in menuList"
        :key="item.id"
      >
        <view
          v-if="item.authorities===true || util.isAuthorities(item.authorities)"
          class="menu-item"
          @tap="toSettingsPage(item.url)"
        >
          <view class="menu-name">
            {{ item.name }}
          </view>
          <uni-icons
            class="ml-auto"
            type="arrowright"
            color="#999999"
          />
        </view>
      </block>
    </view>
    <!-- 退出登录 -->
    <view
      v-if="userInfo.shopStatus===2 && paySettlementType!==1"
      class="logout-btn  apply-online"
      @tap="toSettingsPage('/package-settings/pages/store-settings-apply-online/store-settings-apply-online')"
    >
      申请上线
    </view>
    <view
      class="logout-btn"
      @tap="logout"
    >
      退出登录
    </view>
  </view>
</template>

<script setup>
import util from '@/utils/util'
import { WKSDK } from 'wukongimjssdk'
const paySettlementType = uni.getStorageSync('bbcPaySettlementType')

const userInfo = ref('')
const menuList = [
  {
    name: '基本信息',
    id: 1,
    url: '/package-settings/pages/store-settings-basic/store-settings-basic',
    authorities: 'shop:shopDetail:view'
  },
  {
    name: '工商信息',
    id: 2,
    url: '/package-settings/pages/store-settings-business/store-settings-business',
    authorities: 'shop:shopCompany:view'
  },
  {
    name: '签约信息',
    id: 3,
    url: '/package-settings/pages/store-settings-contract/store-settings-contract',
    authorities: 'shop:shopContract:view'
  },
  {
    name: '财务信息',
    id: 4,
    url: '/package-settings/pages/store-settings-financial/store-settings-financial',
    authorities: 'shop:shopFinancial:view'
  },
  {
    name: '修改密码',
    id: 5,
    url: '/package-settings/pages/find-pwd/find-pwd?edit=1',
    authorities: true
  }
]
let auditingInfoStatus = ref(null)

onShow(() => {
  getUserInfo()
  getAuditingInfo()
})

/**
   * 跳转
   */
const toSettingsPage = (url) => {
  if (url === '/package-settings/pages/store-settings-financial/store-settings-financial' && paySettlementType === 1 && (userInfo.companyInfoProcessStatus === 0 || userInfo.companyInfoProcessStatus === 3)) {
    uni.navigateTo({
      url: '/package-settings/pages/allinpay-store-account/allinpay-store-account'
    })
    return
  }
  uni.navigateTo({
    url
  })
}
/**
   * 退出登录
   */
const logout = async () => {
  await WKSDK.shared().disconnect()
  uni.showLoading()
  const params = {
    url: '/logOut',
    method: 'POST'
  }
  http.request(params).then(() => {
    uni.hideLoading()
    uni.removeStorageSync('bbcToken_us')
    uni.removeStorageSync('bbcLoginResult')
    uni.removeStorageSync('bbcAuthorities')
    uni.redirectTo({
      url: '/pages/login/login'
    })
  })
}
/**
 * 获取用户信息
 */
const getUserInfo = () => {
  http.request({
    url: '/shop/shopDetail/info',
    method: 'GET'

  }).then(({ data }) => {
    userInfo.value = data
  })
}
/**
 * 获取审核状态
 */
const getAuditingInfo = () => {
  http.request({
    url: '/shop/shopDetail/getAuditingInfo',
    method: 'GET'
  }).then(({ data: { status } }) => {
    auditingInfoStatus = status
  })
}

</script>

<style lang="scss" scoped>
@use './store-settings.scss';
</style>
